<!--
 * @Author: wuheng wuheng@szhbzc.com
 * @Date: 2024-12-23 11:16:44
 * @LastEditors: wuheng wuheng@szhbzc.com
 * @LastEditTime: 2025-01-15 09:34:43
 * @FilePath: \web-appc:\Users\wuheng\Desktop\WugangNew\src\views\dishmana\dishbom\components\Consuminfo.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="售价历史" name="first">
        <el-table :data="DishSellingData">
          <el-table-column type="index" label="序号" width="120" />
          <el-table-column prop="createTime" label="日期" width="180" />
          <el-table-column prop="sellPrice" label="售价(元)" />
          <el-table-column prop="creator" label="创建人" />
          <el-table-column prop="totalCost" label="成本(元)" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="投产比历史" name="second">
        <el-table :data="DishSellingData" show-summary>
          <el-table-column type="index" label="序号" width="120" />
          <el-table-column prop="createTime" label="日期" width="180" />
          <el-table-column prop="roi" label="投产比(%)" width="180" />
          <el-table-column prop="creator" label="创建人" />
          <el-table-column prop="totalCost" label="成本(元)" />
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script lang="ts" setup>
import { GetDishSellingApi } from '@/api/Dashmana'
const props = defineProps({
  Bomdata: {
    type: Object,
    default: {}
  }
})
const activeName = ref('first')
const DishSellingData = ref([] as any)
const getBomlistfn = () => {
  GetDishSellingApi({
    "currentPage": 1,
    "pageSize": -1,
    "sortingFields": [
      {
        "field": "",
        "order": ""
      }
    ],
    "dishCode": props.Bomdata.dishCode
  }).then((res: any) => {
    DishSellingData.value = res.data ? res.data.records : []
  })
}
const getSummaries = ({ columns, data }: any) => {
  const sums = [] as any;
  columns.forEach((column: any, index: any) => {
    if (index === 0) {
      // 第一列是ID，不显示总计
      sums[index] = '总计';
      return;
    }
    if (column.property === 'sellPrice' || column.property === 'totalCost') {
      // 只为amount1和amount2计算总计
      const values = data.map(item => Number(item[column.property] || 0));
      const sum = values.reduce((prev, curr) => {
        const value = Number(curr);
        if (!isNaN(value)) {
          return prev + curr;
        } else {
          return prev;
        }
      }, 0);

      sums[index] = sum;
    } else if (column.property === 'roi12321') {
      // 只为amount1和amount2计算总计
      const values = data.map(item => Number(item[column.property] || 0));
      const sum = values.reduce((prev, curr) => {
        const value = Number(curr);
        if (!isNaN(value)) {
          return prev + curr;
        } else {
          return prev;
        }
      }, 0);

      sums[index] = sum;
    } else {
      // 其他列不显示总计
      sums[index] = '';
    }
  });

  return sums;
}
onMounted(() => {
  getBomlistfn()
})
</script>

<style lang="scss" scoped></style>
